



///////////////////////////////////////////////////////
/*
  Project:	
  Platform: STM32F103VGT6
  Author:   Donnie Liang
  Data:     2020.12.30
  Version:  V1.0
  FileName: CRC_Function.c

  CopyRight reserved by 


*/
///////////////////////////////////////////////////////
#include  <string.h>
//#include  "stm32f10x.h"
#include  "stdint.h"
#include "iotv30_config.h"


//#include  <ctype.h>
//#include  <stdio.h> 
//#include  <stdlib.h> 
//#include  <string.h>
//#include "global.h"


#include  "CRC_Function.h"







//CRC16_XMODEM    CRC-16/XMODEM       x16+x12+x5+1
uint16_t CRC16_Xmodem(uint8_t *pucMsg, uint16_t uhwDataLen )
{
	uint8_t  i ;
	uint16_t uhwCRCin = 0x0000;
	uint16_t uhwCPoly = 0x1021;

	uint16_t uhwChar = 0;	

	while ( uhwDataLen-- ) 	
	{
		uhwChar = *(pucMsg++);
		uhwCRCin ^= (uhwChar << 8);
			
		for(i = 0;i < 8;i++)
		{
			if(uhwCRCin & 0x8000)
			{
				uhwCRCin = (uhwCRCin << 1) ^ uhwCPoly;
			}
			else
			{
				uhwCRCin = uhwCRCin << 1;
			}
		
		}
	}
	
	return (uhwCRCin) ;
}





